package nccloud.pubimpl.so.delivery.event.head;

import java.util.List;
import java.util.Map;

import nc.bs.dao.BaseDAO;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.pub.BusinessException;
import nc.vo.so.m4331.entity.DeliveryVO;
import nc.vo.so.pub.keyvalue.VOKeyValue;
import nccloud.dto.scmpub.pub.context.BillCardHeadEditEvent;
import nccloud.dto.scmpub.pub.event.rule.IHeadAfterRule;

public class TrantypeAfterRule extends Object implements IHeadAfterRule<DeliveryVO> {
	public DeliveryVO afterEdit(DeliveryVO billvo, BillCardHeadEditEvent event, Map userobject) {
		try {
			VOKeyValue vOKeyValue = new VOKeyValue(billvo);
			
			String vtrantypecode = vOKeyValue.getHeadStringValue("vtrantypecode");

			String sql = "SELECT a.pk_businesstype FROM pub_billbusiness a,bd_busitype b WHERE a.pk_businesstype = b.pk_busitype AND pk_billtype = '4331' AND a.transtype  = '"+vtrantypecode+"' AND b.validity = 1 ";
			List<Map<String, Object>> mapList = (List<Map<String, Object>>) new BaseDAO().executeQuery(sql, new MapListProcessor());

			if (mapList != null && mapList.size() > 0) {
				for (Map<String, Object> map : mapList) {
					String pk_businesstype = map.get("pk_businesstype").toString();
					vOKeyValue.setHeadValue("cbiztypeid", pk_businesstype);
				}
			}
			
		} catch (BusinessException e) {
			e.printStackTrace();
		}
		return billvo;
	}
}
